import { _decorator, Button, Label, RichText, size, Sprite, UITransform } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import Ab_GameDC_bA from '../../manager/data.game.center';
import Ab_GameAssets_bA from '../../manager/game.assets';
import { Ab_Float_bA } from '../page/float';
import type { Ab_Popup_bA } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('Ab_DrawerLock_bA')
export class Ab_DrawerLock_bA extends Ab_BasePopUp_bA<typeof Ab_Popup_bA, boolean> {
	protected Ab_default_return_bA: boolean;

	private ui_container: UITransform;

	protected Ab_initAfterOnLoad_bA(){
		this.ui_container = this.node.getChildByName('container').getComponent(UITransform);

		this.Ab_renderLocalUI_bA();
	}

	protected Ab__click_event__bA: { [name: string]: (this: Ab_DrawerLock_bA, button: Button) => void; } = {
		async close(btn){
			btn.interactable = false;
			await this.Ab_exit_bA(false);
			btn.interactable = true;
		},
		async pick(btn){
			btn.interactable = false;

			if(Ab_GameDC_bA.Ab_User_bA.Ab_diamond_bA<500){
				await Ab_Float_bA.Ab_Hint_bA(Ab_GameAssets_bA.Ab_getLangText_bA(65));
			}else{
				Ab_GameDC_bA.Ab_Trigger_bA.Ab_CHANGE_DIAMOND_bA = -500;
				//Ab_GameDC_bA.Ab_User_bA.Ab_lock_bA = false;
				await this.Ab_exit_bA(true);
			}

			btn.interactable = true;
		}
	}

	public Ab_onShow_bA(){
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.ui_container.node);
	}

	private Ab_renderLocalUI_bA(){
		this.ui_container.node.getChildByName('richtext').getComponent(RichText).string = Ab_GameAssets_bA.Ab_getLangText_bA(13, '<color=#F5FB03>', '</color>');
		this.ui_container.node.getChildByName('lbl-desc').getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(14);
		this.ui_container.node.getChildByName('lbl-diamond').getComponent(Label).string = '500';

		let ui_title = this.ui_container.node.getChildByName('title').getComponent(UITransform);
		let title_size = size(this.ui_container.width, ui_title.height);
		let sframe = Ab_GameAssets_bA.Ab_getLangTexture_bA(2);

		let scale = Math.min(title_size.width/sframe.originalSize.width, title_size.height/sframe.originalSize.height);

		ui_title.getComponent(Sprite).spriteFrame = sframe;

		ui_title.setContentSize(
			sframe.originalSize.width*scale,
			sframe.originalSize.height*scale
		);
		//let [R, r] = [title_size, sframe.originalSize].map(s=>s.width/s.height);

		//abi.Ab_cc_bA.Ab_skinPeeler_bA(ui_title.node, sframe, (R > r) ? {height: true} : {width: true});
	}

	private async Ab_exit_bA(pick: boolean){
		await Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.ui_container.node);
		this.Ab_close_bA(pick);
	}
}

